//
//  LDSYYYViewControllerViewModel.m
//  TestCategory
//
//  Created by kai_leedarson on 2017/11/8.
//Copyright © 2017年 maple_leedarson. All rights reserved.
//

#import "LDSYYYViewControllerViewModel.h"

@interface LDSYYYViewControllerViewModel ()
@property(nonatomic, strong) NSMutableArray *originDataSource;
@property(nonatomic, strong) NSMutableArray *originSectionDataSource;
@end

@implementation LDSYYYViewControllerViewModel
- (NSMutableArray *)originDataSource {
    if (_originDataSource == nil) {
        _originDataSource = [NSMutableArray array];
        LDSYYYModel *model1 = [LDSYYYModel initWithImageName:@"smartscene_icon_delay" andText:@"延时" andDetail:@"5分0秒"];
        LDSYYYModel *model2 = [LDSYYYModel initWithImageName:@"smartscene_icon_delay" andText:@"延时1" andDetail:@"5分0秒"];
        LDSYYYModel *model3 = [LDSYYYModel initWithImageName:@"smartscene_icon_delay" andText:@"延时2" andDetail:@"5分0秒"];
        LDSYYYModel *model4 = [LDSYYYModel initWithImageName:nil andText:@"00:00-24:00" andDetail:@"每天"];
        model4.changeColor = YES;
        NSArray *modelArray = @[model1,model2,model3];
        NSArray *modelArray2 = @[model4];
        [_originDataSource addObject:@[]];
        [_originDataSource addObject:@[]];
        [_originDataSource addObject:modelArray];
        [_originDataSource addObject:@[]];
        [_originDataSource addObject:modelArray2];
    }
    return _originDataSource;
}

- (NSMutableArray *)originSectionDataSource {
    if (_originSectionDataSource == nil) {
        LDSYYYSectionModel *secModel1 = [[LDSYYYSectionModel alloc] initWithImageName:nil andText:@"条件" andStatus:1];
        LDSYYYSectionModel *secModel2 = [[LDSYYYSectionModel alloc] initWithImageName:nil andText:@"条件" andStatus:2];
        secModel2.rightDetail = @"任意";
        LDSYYYSectionModel *secModel3 = [[LDSYYYSectionModel alloc] initWithImageName:nil andText:@"动作" andStatus:1];
        LDSYYYSectionModel *secModel4 = [[LDSYYYSectionModel alloc] initWithImageName:nil andText:@"开关" andStatus:3];
        LDSYYYSectionModel *secModel5 = [[LDSYYYSectionModel alloc] initWithImageName:nil andText:@"执行周期" andStatus:0];
        secModel5.blueColor = YES;
        _originSectionDataSource = [@[secModel1,secModel2,secModel3,secModel4,secModel5] mutableCopy];
    }
    return _originSectionDataSource;
}

- (void)loadFetchData {
    NSMutableArray *dataSource = [NSMutableArray array];
    for (NSInteger i = 0; i < self.originDataSource.count; i ++) {
        NSArray *sectionArray = self.originDataSource[i];
        NSMutableArray *array = [NSMutableArray array];
        for (NSInteger j = 0; j < sectionArray.count; j++) {
            LDSTableViewCellViewModel *cellviewModel = [LDSTableViewCellViewModel modelCellWithClass:[LDSYYYTableCell class] model:sectionArray[j]  tag:i*10+j];
            cellviewModel.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            cellviewModel.tableViewCellStyle = UITableViewCellStyleValue1;
            [array addObject:cellviewModel];
        }
        [dataSource addObject:array];
    }
    NSMutableArray *sectionDatas = [NSMutableArray array];
    CGRect frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width,55.0f);
    [self.originSectionDataSource enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        LDSViewModel *sectionViewModel = [LDSViewModel modelViewWithClass:[LDSYYYSectionView class] frame:frame model:obj];
        sectionViewModel.xib = YES;
        [sectionDatas addObject:sectionViewModel];
    }];
    self.fetchDataSource = dataSource;
    self.sectionDataSource = sectionDatas;
    [self setUpDataSource];
}

- (void)setUpDataSource {
    if (self.fetchDataSource) {
        self.dataSource = self.fetchDataSource;
        if ([self.delegate respondsToSelector:@selector(lds_didReceiveDataWithDataSource:andSectionDataSource:)]) {
            [self.delegate lds_didReceiveDataWithDataSource:[self.dataSource copy]
                                       andSectionDataSource:[self.sectionDataSource copy]];
        }
    }
}

@end
